package com.voxel.sense.infomsg.view.titlebar;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.voxel.sense.infomsg.R;


public class TextTitleBar extends BaseTitleBar {
	/**
	 * 右边一个图片按扭一个文本按扭 除了返回按扭和标题TextView，其他默认都是隐藏的，设置监听器后默认显示，也可以再次隐藏
	 */
	private TextView tv_right;
	private View titleDivider;

	public TextTitleBar(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		init(context,attrs);
	}
	public TextTitleBar(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context,attrs);
	}
	public TextTitleBar(Context context) {
		super(context);
		init(context,null);

	}

	private void init(final Context context, AttributeSet attrs){
		setBackgroundResource(R.drawable.text_title_bar_bg_color);
		LayoutInflater.from(context).inflate(R.layout.title_bar_text, this,true);
		initBaseView(context,attrs);
		tv_right = (TextView) findViewById(R.id.titlebar_tv_right);
		titleDivider=findViewById(R.id.title_divider);
	}


	public TextTitleBar setRightVisible(boolean visible){
		tv_right.setVisibility(visible? VISIBLE : GONE);
		return this;
	}

	/**
	 * 设置右边按扭图片与监听
	 */
	public TextTitleBar setRightTextAndLis(int resid,View.OnClickListener lis){
		tv_right.setText(resid);
		tv_right.setOnClickListener(lis);
		tv_right.setVisibility(VISIBLE);
		return this;
	}
	public TextTitleBar setRightTextAndLis(CharSequence text, View.OnClickListener lis){
		tv_right.setText(text);
		tv_right.setOnClickListener(lis);
		tv_right.setVisibility(VISIBLE);
		return this;
	}

	public TextTitleBar setRightText(int resid) {
		tv_right.setText(resid);
		return this;
	}

	public TextTitleBar setRightText(CharSequence text) {
		tv_right.setText(text);
		tv_right.setVisibility(VISIBLE);
		return this;
	}

	public TextTitleBar setRightTextColor(int color) {
		tv_right.setTextColor(color);
		return this;
	}

	public TextView getTv_right() {
		return tv_right;
	}

	public void setTitleDividerVisiable(boolean visiable){
		if (visiable) {
			titleDivider.setVisibility(VISIBLE);
		}else titleDivider.setVisibility(GONE);
	}
}
